﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<VCC.CMS.ViewModels.ShopIndexCMSViewModel>" %>
<%@ Import Namespace="VCC.Lib.Helpers" %>
<%@ Import Namespace="VCC.Lib.Paging" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách gian hàng
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Header" runat="server">
    Danh sách gian hàng
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Message" runat="server">
<%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Toolbar" runat="server">
    <td>
        <%= Html.Toolbar("Thêm mới", "/Shop/CreateCms", "new") %>
    </td>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%if (ViewData["MessageInfo"] == null)
      { %>
    <form action="/Shop/IndexCms" method="post" name="adminForm">
    <table width="100%">
        <tr>
            <td align="left" width="30%">
                Tìm nhanh
                <%= Html.TextBox("Keyword", Model.Keyword) %>
                <%= Html.ActionImageJS("Tìm kiếm", "icon-32-search.png", "document.adminForm.submit();", false)%>
            </td>
            <td align="right">
                <%=Html.DropDownList("CatID", new SelectList(Model.CategoryBuiltTree, "Value", "Text", Model.CurentCateId).ToList(), "Danh mục", new { onchange = "document.adminForm.submit();",style="width:90px" })%>
                <%=Html.DropDownList("AreaID", new SelectList(Model.Areas, "ID", "Name", Model.CurentAreaId).ToList(), "-- Khu vực --", new { onchange = "document.adminForm.submit();", style = "width:90px" })%>
                <%=Html.DropDownList("CityID", new SelectList(Model.Cities, "ID", "Name", Model.CurentCityId).ToList(), "-Tỉnh/thành-", new { onchange = "document.adminForm.submit();", style = "width:100px" })%>
                <%=Html.DropDownList("DistrictID", new SelectList(Model.Districts, "ID", "Name", Model.CurentDistrictId).ToList(), "-Quận/huyện-", new { onchange = "document.adminForm.submit();", style = "width:100px" })%>
                <%=Html.DropDownList("PubStatusId", new SelectList(Model.PubStatus, "Key", "Value", Model.CurentPubStatusId).ToList(), "-Xuất bản-", new { onchange = "document.adminForm.submit();", style = "width:80px" })%>
                <%=Html.DropDownList("ForcusId", new SelectList(Model.ForcusStatus, "Key", "Value", Model.CurentForcusId).ToList(), "Trạng thái", new { onchange = "document.adminForm.submit();", style = "width:90px" })%>
            </td>
        </tr>
    </table>
    <table width="100%" class="adminlist">
        <thead>
            <tr>
                <th width="10" align="right">
                    STT
                </th>
                <th width="30">
                </th>
                <th width="30">
                </th>
                <th>
                    Có tất cả <b><font color="red"><%=Html.Encode(Model.Shops != null ? Model.Shops.TotalItemCount : 0)%></font></b> gian hàng
                </th>
                <th style="width: 100px">
                    <%= Html.Sort("Ngày đăng", "OpenDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 100px">
                    <%= Html.Sort("Ngày hạ", "CloseDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 20px; color: #1D60FF;">
                    Xuất bản
                </th>
                <th style="width: 20px; color: #1D60FF;">
                    GH tiêu biểu
                </th>
                <%--<th style="width: 20px; color: #1D60FF;">
                    Làm mới
                </th>--%>
                <%--<th style="width: 20px">
                    Send mail
                </th>--%>
                <th style="width: 40px">
                    <%= Html.Sort("ID", "ID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
            </tr>
        </thead>
        <tbody>
            <% 
                int i = Model.Shops != null ? Model.Shops.PageSize * Model.Shops.PageIndex : 0;
                if (Model.Shops != null)
          {
              foreach (var item in Model.Shops)
              {
                  i++;
            %>
            <tr id="tr_<%=item.ID%>">
                <td align="right">
                    <%= i.ToString()%>
                </td>
                <td align="center">
                    <%= Html.ActionImage("Sửa", "icon-24-edit.png", "Shop", "EditCms", new Dictionary<string, object>() { { "id", item.ID } })%>
                </td>
                <td align="center">
                    <img alt="Xóa giá trị" src="/Images/icon-24-delete.png" onclick="DelShop(<%=item.ID %>);" />
                </td>
                <td>
                    <div>
                        <div class="aditem">
                            <div class="imageAvatar">
                                <a href="/Shop/DetailsCms/<%= item.ID %>"><img width="60" height="55" src="<%=VCC.Lib.Common.LinkUtils.UrlImageOrDefault(item.LogoPath)%>" title="" alt="" /></a>
                            </div>
                            <div class="summary">
                                    <a href="/Shop/DetailsCms/<%= item.ID %>"><%=Html.Encode(item.Name)%></a><br />
                                    <%= Html.Encode(item.City.Name)%><br />
                                    <span class="contactInfo">Người đăng:<span class="lightLale"><%=Html.Encode(item.NameContact)%></span>
                                    Sđt:<span class="lightLale"><%=Html.Encode(item.MobileContact)%></span>
                                      Email:<span class="lightLale"><%=Html.Encode(item.EmailContact)%></span>
                                      </span>
                            </div>
                        </div>
                    </div>
                </td>
                <td>
                    <%= Html.Encode(string.Format("{0:dd/MM/yyyy HH:mm}", item.OpenDate))%>
                </td>
                <td>
                    <%= Html.Encode(string.Format("{0:dd/MM/yyyy HH:mm}", item.CloseDate))%>
                </td>
                <td align="center">
                    <img alt="" id="imgPubYN_<%= item.ID %>" onclick="ChangePubYN(<%= item.ID %>);" value="<%= item.PubYN %>"
                        src="<%= item.PubYN == true ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>
                <td align="center">
                    <img alt="" id="imgFocusYN_<%= item.ID %>" onclick="ChangeFocusYN(<%= item.ID %>);" value="<%= item.FocusYN %>"
                        src="<%= item.FocusYN == true ?"/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>
                <%--<td align="center">
                    <img alt="Làm mới tin" id="" onclick="RefreshAd(<%= item.ID %>);" src="/Images/refresh.jpg" />
                </td>--%>
                <%--<td align="center">
                    <img alt="<%=item.SendEmailYN.HasValue == true ? "Đã gửi mail cho khách hàng" : "Chưa gửi mail cho khách hàng" %>" src="<%= item.SendEmailYN.HasValue == true ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>--%>
                <td>
                    <%= Html.Encode(item.ID)%>
                </td>
            </tr>
            <% }
          } %>
        </tbody>
    </table>
    <%= Html.Hidden("order")%>
    <%= Html.Hidden("orderDir")%>
    <table width="100%">
        <tr>
            <td align="center">
                <div class="pager">
                    <label>
                        Hiển thị #</label>
                    <%
                        int[] pageSizeList = { 1, 5, 10, 15, 20, 25, 50, 100 };
                    %>
                    <%= Html.DropDownList("PageSize", new SelectList(pageSizeList, Model.Shops != null ? Model.Shops.PageSize : 0), new { onchange = "document.adminForm.submit();" })%>
                    <%= Html.Pager(Model.Shops != null ? Model.Shops.PageSize : 0, Model.Shops != null ? Model.Shops.PageNumber : 0, Model.Shops != null ? Model.Shops.TotalItemCount : 0, "IndexCms")%>
                </div>
            </td>
        </tr>
    </table>
    </form>
    <% } %>

    <script type="text/javascript">
        function ChangePubYN(id) {
            var obj = $("#imgPubYN_" + id);
            ApplyChangeYN("/Applications/ApplyChangeYN/ApChangeYN/" + "Shop" + '/' + "PubYN" + '/' + id + '/' + obj.attr("value"), id, obj);
        }
        function ChangeFocusYN(id) {
            var obj = $("#imgFocusYN_" + id);
            ApplyChangeYN("/Applications/ApplyChangeYN/ApChangeYN/" + "Shop" + '/' + "FocusYN" + '/' + id + '/' + obj.attr("value"), id, obj);
        }
//        function RefreshAd(id) {
//            var ur = "/Ad/RefreshAd/" + id;
//            if (confirm("Bạn có chắc chắn muốn làm mới tin rao này?")) {
//                $.ajax({
//                    url: ur,
//                    type: 'POST',
//                    success: function(html) {
//                        if (html.toString() == "true") {
//                            alert("Đã làm mới tin rao thành công!");
//                            window.location.reload(true);
//                        }
//                    },
//                    error: function(mes) {
//                        alert("Lỗi: Làm mới tin rao không thành công!");
//                        return false;
//                    }
//                });
//            }
//        }
        function DelShop(id) {
            Del(id, 'Shop');
        } 
    </script>

</asp:Content>




